package com.qing.administer.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

@Data
@Getter
@Setter
@AllArgsConstructor
public class ResultInfo implements Serializable {


    private Integer code;

    private String message;

    private Object data;

    private Long timestamp=System.currentTimeMillis();

    public ResultInfo() {
    }

    public static ResultInfo setResultCode(CommonEnum resultCode){
        ResultInfo resultInfo =new ResultInfo();
        resultInfo.setCode(resultCode.getCode());
        resultInfo.setMessage(resultCode.getMessage());
        return resultInfo;
    }


    public static ResultInfo success(){
        return setResultCode(ResultCode.SUCCESS);
    }

    public static ResultInfo success(Object data){
        ResultInfo resultInfo =setResultCode(ResultCode.SUCCESS);
        resultInfo.setData(data);
        return resultInfo;
    }

    public static ResultInfo failure(CommonEnum resultCode){
        return setResultCode(resultCode);
    }

    public static ResultInfo failure(CommonEnum resultCode, Object data){
        ResultInfo resultInfo =setResultCode(resultCode);
        resultInfo.setData(data);
        return resultInfo;
    }

    public static ResultInfo failure(Integer code, String message, Object data){
        ResultInfo resultInfo =new ResultInfo();
        resultInfo.setCode(code);
        resultInfo.setMessage(message);
        resultInfo.setData(data);
        return resultInfo;
    }

    public static ResultInfo failure(Integer code, String message){
        ResultInfo resultInfo =new ResultInfo();
        resultInfo.setCode(code);
        resultInfo.setMessage(message);
        return resultInfo;
    }

}
